//
//  NMPOFuncMainFunCell.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPOFuncMainFunCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(nmpo_collectionView)
        nmpo_collectionView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_collectionView.register(NMPOFuncTypeCell.classForCoder(), forCellWithReuseIdentifier: NMPOFuncTypeCell.nmpo_viewToString)
        nmpo_collectionView.dataSource = self
        nmpo_collectionView.delegate = self
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - nmpo lazy
    @objc  func nmpo_layout() -> UICollectionViewFlowLayout {
        let nmpo_layout = UICollectionViewFlowLayout()
        nmpo_layout.itemSize =  CGSize(width: 108, height: 112)
        return nmpo_layout
    }
    
    lazy var nmpo_collectionView: UICollectionView = {
        let nmpo_collectionView = UICollectionView.init(frame: .zero, collectionViewLayout: nmpo_layout())
        nmpo_collectionView.backgroundColor = .clear
        nmpo_collectionView.showsVerticalScrollIndicator = false
        nmpo_collectionView.showsHorizontalScrollIndicator = false
        nmpo_collectionView.contentInsetAdjustmentBehavior = .never
        return nmpo_collectionView
    }()
    lazy var nmpo_funcModels: [NMPOFuncModel] = {
        var nmpo_funcModels = [NMPOFuncModel]()
        nmpo_funcModels.append(NMPOFuncModel(nmpo_type: .nmpo_speed, nmpo_title: "Speed test" ,nmpo_icon: "nmpo_result_connectSpeed"))
        nmpo_funcModels.append(NMPOFuncModel(nmpo_type: .nmpo_device, nmpo_title: "Device infor" ,nmpo_icon: "nmpo_func_device"))
        nmpo_funcModels.append(NMPOFuncModel(nmpo_type: .nmpo_ip, nmpo_title: "IP check" ,nmpo_icon: "nmpo_result_connectIP"))
        return nmpo_funcModels
    }()

}
// MARK: - lazy UICollectionViewDataSource UICollectionViewDelegateFlowLayout
extension NMPOFuncMainFunCell: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return nmpo_funcModels.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let nmpo_funcModel = nmpo_funcModels[indexPath.row]
        let nmpo_cell = collectionView.dequeueReusableCell(withReuseIdentifier: NMPOFuncTypeCell.nmpo_viewToString, for: indexPath) as! NMPOFuncTypeCell
        nmpo_cell.nmpo_funcModel = nmpo_funcModel
        return nmpo_cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let nmpo_funcModel = nmpo_funcModels[indexPath.row]
        nmpo_viewGetVController?.navigationController?.pushViewController(NMPOScanViewController(nmpo_funcType: nmpo_funcModel.nmpo_type), animated: true)
    }
}
